package nl.haemers.data.reflection 
{
	import flash.utils.Dictionary;
	import nl.haemers.data.collections.List;
	import nl.haemers.data.constants.ReflectionConstants;
	import nl.haemers.data.reflection.Accessor;
	import nl.haemers.data.reflection.IAccessor;
	/**
	 * ...
	 * @author Jonathan Haemers
	 * These are the Getters & Setters of an object
	 */
	public class Accessors implements IAccessors 
	{		
		private var _list							:List;
		
		public function Accessors(description:XML) 
		{
			_list = new List();
			init(description);
		}
		
		/** Public methods **/
		public function getAccessor(name:String) : IAccessor 
		{
			return _list.search(name) as IAccessor;
		}
		
		public function hasAccessor(name:String) : Boolean
		{
			return _list.hasKey(name);
		}
		
		public function getAccessors() : Dictionary
		{
			return _list.items;
		}
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		private function addAccessor(name:String, accessor:Accessor) : Boolean
		{
			return _list.add(name, accessor);
		}
		//TODO: Maybe we need to make this a public method, because it's not good for perfomance to do heavy code in the constructor.
		private function init(xml:XML) : Boolean
		{
			if (xml.hasComplexContent())
			{				
				for each(var node:XML in xml.elements(ReflectionConstants.XML_ACCESSOR))
				{
					var accessor:Accessor = new Accessor(node);
					//TODO: Check if we could use propertynames instead of name
					//_list.add(accessor.name, accessor);
					_list.add(accessor.name, accessor);
					//this.addAccessor(accessor.toString(), accessor);
				}
			}
			return true;
		}
		
	}

}